<?php

namespace App\Controller\Admin;
use App\Controller\ApiController;
use Hyperf\Di\Annotation\Inject;
use Hyperf\Logger\LoggerFactory;
use Psr\Http\Message\ResponseInterface;
use Psr\Log\LoggerInterface;
use App\Logic\Admin\RolesLogic;
use Throwable;

class RolesController extends ApiController
{
    #[Inject]
    protected LoggerInterface $logger;
    #[Inject]
    protected RolesLogic $rolesLogic;
    public function __construct(LoggerFactory $loggerFactory)
    {
        parent::__construct($loggerFactory);
        $this->rolesLogic = new \App\Logic\Admin\RolesLogic();
    }

    /**
     * Notes:获取角色列表
     * 2025/7/15
     * @return ResponseInterface
     * @throws \Exception
     */
    public function list():\Psr\Http\Message\ResponseInterface
    {
        try {
            $result = $this->rolesLogic->list();
            return $this->responseSuccess($result);
        }catch (Throwable $throwable){
            return $this->responseError($throwable->getCode(),$throwable->getLine(),$throwable->getFile() ,$throwable->getMessage());
        }
    }

    /**
     * Note:获取角色详情
     * User: Kong
     * Date: 2025/9/25
     * Time: 12:29
     * @return ResponseInterface
     * @throws \Exception
     */
    public function detail():\Psr\Http\Message\ResponseInterface
    {
        try {
            $result = $this->rolesLogic->detail($this->request->all());
            return $this->responseSuccess($result);
        }catch (Throwable $throwable){
            return $this->responseError($throwable->getCode(),$throwable->getLine(),$throwable->getFile() ,$throwable->getMessage());
        }
    }

    /**
     * Note:创建角色
     * User: Kong
     * Date: 2025/9/25
     * Time: 12:32
     * @return ResponseInterface
     * @throws \Exception
     */
    public function create():\Psr\Http\Message\ResponseInterface
    {
        try {
            $result = $this->rolesLogic->create($this->request->all());
            return $this->responseSuccess($result);
        }catch (Throwable $throwable){
            return $this->responseError($throwable->getCode(),$throwable->getLine(),$throwable->getFile() ,$throwable->getMessage());
        }
    }

    /**
     * Note:修改角色
     * User: Kong
     * Date: 2025/9/25
     * Time: 12:32
     * @return ResponseInterface
     * @throws \Exception
     */
    public function update():\Psr\Http\Message\ResponseInterface
    {
        try {
            $result = $this->rolesLogic->update($this->request->all());
            return $this->responseSuccess($result);
        }catch (Throwable $throwable){
            return $this->responseError($throwable->getCode(),$throwable->getLine(),$throwable->getFile() ,$throwable->getMessage());
        }
    }

    /**
     * Note:删除角色
     * User: Kong
     * Date: 2025/9/25
     * Time: 12:32
     * @return ResponseInterface
     * @throws \Exception
     */
    public function destroy():\Psr\Http\Message\ResponseInterface
    {
        try {
            $result = $this->rolesLogic->destroy($this->request->all());
            return $this->responseSuccess($result);
        }catch (Throwable $throwable){
            return $this->responseError($throwable->getCode(),$throwable->getLine(),$throwable->getFile() ,$throwable->getMessage());
        }
    }
}